package requests

import (
	"github.com/gin-gonic/gin"
	"github.com/thedevsaddam/govalidator"
)

type LoginRequest struct {
	Email    string `json:"email,omitempty" valid:"email"`
	Tel      string `json:"tel,omitempty" valid:"email"`
	Password string `json:"password,omitempty" valid:"password"`
}

func LoginValidate(data interface{}, c *gin.Context) map[string][]string {
	// 自定义验证规则
	rules := govalidator.MapData{
		"email":    []string{"email"},
		"tel":      []string{"tel"},
		"password": []string{"required"},
	}

	// 自定义验证出错时的提示
	messages := govalidator.MapData{
		"email": []string{
			"email:邮箱格式错误",
		},
		"tel": []string{
			"tel:电话号码格式错误",
		},
		"password": []string{
			"required:密码必须填写",
		},
	}
	return validate(data, rules, messages)
}
